You use an implicit operator that converts the string value to a struct value:
public struct MyStruct {
public string s;
public int length;
public static implicit operator MyStruct(string value) {
return new MyStruct() { s = value, length = value.Length };
}
}
Example:
MyStruct myStruct = "Lol";
Console.WriteLine(myStruct.s);
Console.WriteLine(myStruct.length);
Output:
Lol
3